function animation(duration, to, callback) {
  let value = 0;
  let current = 0;
  const start = Date.now();
  let toK = to > 1000 ? 1 : 1000 / to  

  function run() {
    const t = Date.now() - start;
    if (t >= duration) {
      value = to;
      callback(value);
      return;
    }
    const scale = t / toK
    current = scale < 1 ? 0 : to - Math.floor(to / scale)
    const timeId = setTimeout(() => {
      callback(current);
      run()
      clearInterval(timeId);
    }, 10)
  }
  run();
}

Page({
  clickValue(e) {
    animation(1000, 10, (value) => {
      this.setData({
        value
      })
    });
  },
  data: {
    value: 0,
    test: false,
    count: 0,
  },
  onLoad() {
    this.animateNumber();
  },
  animateNumber() {
    let currentNumber = 0;
    const interval = setInterval(() => {
      if (currentNumber < 100) {
        currentNumber++;
        this.setData({
          count: currentNumber,
        });
      } else {
        clearInterval(interval);
      }
    }, 10);
  },
});